// 在键盘按下并释放及提交后验证提交表单
$("#signupForm").validate({
    errorPlacement: function (error, element) {
        // Append error within linked label
        $(element)
            .closest("form")
            .find("label[for='" + element.attr("id") + "']")
            .append(error);
    },
    onkeyup: null,
    errorElement: "span",
    success: function (label) {
        /*label的默认正确样式为valid，需要通过validClass来重置，否则这里添加的其他样式不能被清除*/
        label.text('').addClass('success');
    },
    rules: {
        name: {
            required: true,
            rangelength: [5, 10]
        },
        email: {
            required: true,
            email: true
        },
        phone: {
            required: true,
            isMobile: true
        },
        password: {
            required: true,
            minlength: 5
        },
        password_confirmation: {
            required: true,
            equalTo: '#password'
        }
    },
    messages: {
        email: {
            required: "请输入邮箱",
            email: '请输入正确的邮箱'
        },
        name: {
            required: "请输入用户名",
            rangelength: "用户名不能小于五位同时不能大于十位"
        },
        phone: {
            required: "请输入手机号",
            isMobile: '请输入正确的手机号'
        },
        password: {
            required: '请输入密码',
            minlength: '密码不能少于五位'
        },
        password_confirmation: {
            required: '请输入确认密码',
            equalTo: '两次密码不一样'
        }
    }
})


// 手机号码验证
jQuery.validator.addMethod("isMobile", function (value, element) {
    var length = value.length;
    var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "请正确填写您的手机号码");